package com.mf.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.mf.cloud.apis.PayFeignApi;
import com.mf.cloud.entites.PayDTO;
import com.mf.cloud.resp.ResultData;
import com.mf.cloud.resp.ReturnCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * ClassName: OrderController
 * Package: com.mf.cloud.controller
 *
 * @Author: lmf
 * @Create: 2024/3/10 11:45
 * @Version: 1.0
 * Description: 订单控制层
 */

@RestController  // 将 return 中的内容以 JSON字符串的形式返回客户端
@RequestMapping("/feign/pay")
@Tag(name = "feign用户支付")
public class OrderController {
    @Resource
    private PayFeignApi payFeignApi;
    @Operation(summary = "新增")
    @PostMapping("/add")
    public ResultData addOrder(@RequestBody PayDTO payDTO){
        return payFeignApi.addPay(payDTO);
    }

    @Operation(summary = "根据id查询") //
    @GetMapping("/select/{id}")
    public ResultData<PayDTO> getPay(@PathVariable Integer id){
        ResultData resultData = null;
        try{
            System.out.println("开始调用" + DateUtil.now());
            resultData =  payFeignApi.getPay(id);
        }catch (Exception e){
            System.out.println("开始结束"+ DateUtil.now());
            e.printStackTrace();
            resultData = ResultData.fail(ReturnCodeEnum.RC500.getCode());
        }

        return resultData;
    }
    @Operation(summary = "负载均衡测试")

    @GetMapping("/get/info")
    public String mylb(){
        return payFeignApi.mylb();
    }


}
